package cn.dhnapplets.controller;


import cn.dhnapplets.entity.HorsemanOrder;
import cn.dhnapplets.entity.Result;

import cn.dhnapplets.service.HorsemanOrderService;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 邱文彬
 * @Date 2021/11/17 9:44
 * @Version 1.0
 */


@RestController
public class HosermanOrderController {

    @Autowired
    private HorsemanOrderService horsemanOrderService;

    //    今日
    @ApiOperation(value = "今日")
    @RequestMapping(value = "getHorsemanToday", method = RequestMethod.GET)
    public Result getHorsemanToday(@RequestParam("openId") String openId) {
        HorsemanOrder horsemanOrder = horsemanOrderService.getHorsemanToday(openId);

        return new Result(0, "操作成功", horsemanOrder);
    }

    //    今周
    @ApiOperation(value = "今周")
    @RequestMapping(value = "getHorsemanThisWeek", method = RequestMethod.GET)
    public Result getHorsemanThisWeek(@RequestParam("openId") String openId) {
        HorsemanOrder horsemanOrder = horsemanOrderService.getHorsemanThisWeek(openId);

        return new Result(0, "操作成功", horsemanOrder);
    }

    //    今月
    @ApiOperation(value = "今月")
    @RequestMapping(value = "getHorsemanThisMonth", method = RequestMethod.GET)
    public Result getHorsemanThisMonth(@RequestParam("openId") String openId) {
        HorsemanOrder horsemanOrder = horsemanOrderService.getHorsemanThisMonth(openId);

        return new Result(0, "操作成功", horsemanOrder);
    }

    //    今年
    @ApiOperation(value = "今年")
    @RequestMapping(value = "getHorsemanThisYear", method = RequestMethod.GET)
    public Result getHorsemanThisYear(@RequestParam("openId") String openId) {
        HorsemanOrder horsemanOrder = horsemanOrderService.getHorsemanThisYear(openId);

        return new Result(0, "操作成功", horsemanOrder);
    }

    //    按时间查询
    @ApiOperation(value = "按时间查询")
    @RequestMapping(value = "getHorsemanOrderByTime", method = RequestMethod.POST)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public   Result  getHorsemanOrderByTime(@RequestParam("openId")
                                                        String openId,
                                            @RequestParam(value = "startTime",
                                                    required = false)
                                                    String startTime,
                                            @RequestParam(value = "finishTime",
                                                    required = false)
                                                        String finishTime,
                                            @RequestParam(required = false)
                                                        Integer code) {
        if (code == null && startTime.equals("") && finishTime.equals("")) {
            return new Result(0, "操作失败,时间与状态必填一位", null);
        }

        if (code != null) {
            if (code == 0) {
                return getHorsemanToday(openId);
            } else if (code == 1) {
                return getHorsemanThisWeek(openId);
            } else if (code == 2) {
                return getHorsemanThisMonth(openId);
            } else if (code == 3) {
                return getHorsemanThisYear(openId);
            }
        }

        HorsemanOrder horsemanOrder = horsemanOrderService.getHorsemanOrderByTime(openId, startTime, finishTime);

        return new Result(0, "操作成功", horsemanOrder);
    }

}
